#if (FEATURE_MODE == 0)
/**
 @file ctc_srv6_cli.c

 @date 2019-1-1

 @version v6.0

 The file apply clis of srv6 module
*/

#include "sal.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_debug.h"
#include "ctc_error.h"
#include "ctc_api.h"
#include "ctcs_api.h"
#include "ctc_srv6.h"



CTC_CLI(ctc_cli_srv6_my_sid,
        ctc_cli_srv6_my_sid_cmd,
        "srv6 (add|update|remove) (my-sid SID (mask-len LEN|)) (sid-format FORMAT|) (type TYPE|) \
        {nhid NHID | fid FID | vrf VRFID |logic-port LOGIC_PORT| virtual-port-type|deny-learning| acl-use-outer\
          | psp |ttl-check|use-outer-ttl|stats STATS_ID|scl-id SCL_ID|policer-id POLICERID|use-flex\
          | copy-to-cpu|discard|usp|coc|inner-router-mac MAC|de-masq|"CTC_CLI_PP_BMP"\
          |edit-type EDIT_TYPE|ligality-check-disable|decap|inner-pkt-type TYPE|usd|} ",
        CTC_CLI_SRV6_M_STR,
        "Add my sid table",
        "Update my sid table",
        "Remove my sid table",
        "My sid",
        "SID",
        "My sid mask length",
        "Mask length",
        "SID Format",
        "SID Format",
        "Function type of the SID",
        "Function type of the SID",
        CTC_CLI_NH_ID_STR,
        CTC_CLI_NH_ID_STR,
        CTC_CLI_FID_DESC,
        CTC_CLI_FID_ID_DESC,
        CTC_CLI_VRFID_DESC,
        CTC_CLI_VRFID_ID_DESC,
        "Logic port",
        "Logic port value",
        "Virtual port type",
        "Deny learning",
        "Use outer header info do acl lookup, default use the inner",
        "PSP enable",
        "Do ttl check",
        "Use outer ttl for later process , or use inner ttl",
        CTC_CLI_STATS_ID_DESC,
        CTC_CLI_STATS_ID_VAL,
        "Scl ID",
        CTC_CLI_SCL_ID_VALUE,
        "Policer id",
        CTC_CLI_QOS_FLOW_PLC_VAL,
        "Use flex key",
        "Copy to cpu",
        "Discard the packet",
        "USP enable",
        "COC enabel",
        "Inner router mac",
        "Inner router mac",
        "De-masquerading for END.AM",
        CTC_CLI_PP_BMP_DESC,
        "Edit Type",
        "Edit Type Value",
        "Disable ligality check",
        "Enable decap",
        "Inner packet type",
        "Inner packet type value",
        "USD enable")
{

    ctc_srv6_sid_t my_sid;
    uint32 index = 0xFF;
    int32 ret = CLI_ERROR;
    ipv6_addr_t ipv6_address;

    sal_memset(&my_sid, 0 ,sizeof(ctc_srv6_sid_t));
    index = CTC_CLI_GET_ARGC_INDEX("sid-format");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sid-format", my_sid.format, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("type");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("type", my_sid.type, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("nhid");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("nhid", my_sid.nh_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("fid");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("fid", my_sid.fid, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("vrf");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("vrfid", my_sid.vrf_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("logic-port", my_sid.logic_port, argv[index + 1]);
    }

     index = CTC_CLI_GET_ARGC_INDEX("virtual-port-type");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_LOGIC_PORT_TYPE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("deny-learning");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_DENY_LEARNING);
    }
    index = CTC_CLI_GET_ARGC_INDEX("acl-use-outer");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_ACL_LKUP_BY_OUTER_HEAD);
    }
    index = CTC_CLI_GET_ARGC_INDEX("psp");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_PSP_EN);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ttl-check");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_TTL_CHECK);
    }

    index = CTC_CLI_GET_ARGC_INDEX("use-outer-ttl");
    if (0xFF != index)
    {
            CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_USE_OUTER_TTL);
    }

    index = CTC_CLI_GET_ARGC_INDEX("use-flex");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_USE_FLEX);
    }

    index = CTC_CLI_GET_ARGC_INDEX("stats");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("stats", my_sid.stats_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("scl-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("scl-id", my_sid.scl_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("policer-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("policer-id", my_sid.policer_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("copy-to-cpu");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_COPY_TO_CPU);
    }

    index = CTC_CLI_GET_ARGC_INDEX("discard");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_DISCARD);
    }

    index = CTC_CLI_GET_ARGC_INDEX("usp");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_USP_EN);
    }

    index = CTC_CLI_GET_ARGC_INDEX("coc");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_COC_EN);
    }

    index = CTC_CLI_GET_ARGC_INDEX("inner-router-mac");
    if (0xFF != index)
    {
        CTC_CLI_GET_MAC_ADDRESS("mac address", my_sid.route_mac, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("de-masq");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_DE_MASQ);
    }
    index = CTC_CLI_GET_ARGC_INDEX("edit-type");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("edit-type", my_sid.edit_type, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ligality-check-disable");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_LEGALITY_CHECK_DIS);
    }
    index = CTC_CLI_GET_ARGC_INDEX("decap");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_DECAP_EN);
    }
    index = CTC_CLI_GET_ARGC_INDEX("inner-pkt-type");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("inner-pkt-type", my_sid.inner_pkt_type, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("usd");
    if (0xFF != index)
    {
        CTC_SET_FLAG(my_sid.flag, CTC_SRV6_SID_FLAG_USD_EN);
    }

    index = CTC_CLI_GET_ARGC_INDEX("my-sid");
    if (0xFF != index)
    {
        CTC_CLI_GET_IPV6_ADDRESS("my-sid", ipv6_address, argv[index + 1]);
        my_sid.sid[0] = sal_htonl(ipv6_address[0]);
        my_sid.sid[1] = sal_htonl(ipv6_address[1]);
        my_sid.sid[2] = sal_htonl(ipv6_address[2]);
        my_sid.sid[3] = sal_htonl(ipv6_address[3]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("mask-len");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("mask-len", my_sid.masklen, argv[index + 1]);
    }
    CTC_CLI_GET_PP_BMP(index, my_sid.pp_bmp);
    index = CTC_CLI_GET_ARGC_INDEX("add");
    if (0xFF != index)
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_srv6_add_my_sid(g_api_ldev, &my_sid);
        }
        else
        {
            ret = ctc_srv6_add_my_sid(&my_sid);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("update");
    if (0xFF != index)
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_srv6_update_my_sid(g_api_ldev, &my_sid);
        }
        else
        {
            ret = ctc_srv6_update_my_sid(&my_sid);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("remove");
    if (0xFF != index)
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_srv6_remove_my_sid(g_api_ldev, &my_sid);
        }
        else
        {
            ret = ctc_srv6_remove_my_sid(&my_sid);
        }
    }

    if (ret)
    {
        ctc_cli_out("%% %s \n\r", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    index = CTC_CLI_GET_ARGC_INDEX("add");
    if (0xFF != index)
    {
        ctc_cli_out("%% The allocate scl entry id is 0x%x\n", my_sid.scl_entry_id);
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_srv6_debug_on,
        ctc_cli_srv6_debug_on_cmd,
        "debug srv6 (ctc | sys) (debug-level {func|param|info|error} |)",
        CTC_CLI_DEBUG_STR,
        CTC_CLI_SRV6_M_STR,
        "Ctc layer",
        "Sys layer",
        CTC_CLI_DEBUG_LEVEL_STR,
        CTC_CLI_DEBUG_LEVEL_FUNC,
        CTC_CLI_DEBUG_LEVEL_PARAM,
        CTC_CLI_DEBUG_LEVEL_INFO,
        CTC_CLI_DEBUG_LEVEL_ERROR)
{
    uint32 typeenum = 0;
    uint8 level = CTC_DEBUG_LEVEL_INFO;
    uint8 index = 0;

    index = CTC_CLI_GET_ARGC_INDEX("debug-level");
    if (index != 0xFF)
    {
        level = CTC_DEBUG_LEVEL_NONE;
        index = CTC_CLI_GET_ARGC_INDEX("func");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_FUNC;
        }

        index = CTC_CLI_GET_ARGC_INDEX("param");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_PARAM;
        }

        index = CTC_CLI_GET_ARGC_INDEX("info");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_INFO;
        }

        index = CTC_CLI_GET_ARGC_INDEX("error");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_ERROR;
        }
    }
    else
    {
        level = CTC_DEBUG_LEVEL_FUNC | CTC_DEBUG_LEVEL_INFO | CTC_DEBUG_LEVEL_PARAM | CTC_DEBUG_LEVEL_ERROR;
    }

    if (0 == sal_memcmp(argv[0], "ctc", 3))
    {
        typeenum = SRV6_CTC;
    }
    else if (0 == sal_memcmp(argv[0], "sys", 3))
    {
        typeenum = SRV6_SYS;
    }

    ctc_debug_set_flag("srv6", "srv6", typeenum, level, TRUE);

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_srv6_debug_off,
        ctc_cli_srv6_debug_off_cmd,
        "no debug srv6 (ctc | sys)",
        CTC_CLI_NO_STR,
        CTC_CLI_DEBUG_STR,
        CTC_CLI_SRV6_M_STR,
        "Ctc layer",
        "Sys layer")
{
    uint32 typeenum = 0;
    uint8 level = 0;

    if (0 == sal_memcmp(argv[0], "ctc", 3))
    {
        typeenum = SRV6_CTC;
    }
    else if (0 == sal_memcmp(argv[0], "sys", 3))
    {
        typeenum = SRV6_SYS;
    }

    ctc_debug_set_flag("srv6", "srv6", typeenum, level, FALSE);

    return CLI_SUCCESS;
}


int32
ctc_srv6_cli_init(void)
{
    install_element(CTC_SDK_MODE, &ctc_cli_srv6_my_sid_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_srv6_debug_on_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_srv6_debug_off_cmd);

    return CLI_SUCCESS;
}
#endif

